﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:Converters="clr-namespace:Fluent.Converters" xmlns:internal="clr-namespace:Fluent.Internal">
    <Style x:Key="RibbonContextualTabGroupStyle"
           TargetType="{x:Type Fluent:RibbonContextualTabGroup}">
        <Setter Property="Template"
                Value="{DynamicResource RibbonContextualTabGroupControlTemplate}" />
        <Setter Property="Width"
                Value="Auto" />
        <Setter Property="HorizontalAlignment"
                Value="Stretch" />
        <Setter Property="Focusable"
                Value="False" />
    </Style>
    <ControlTemplate x:Key="RibbonContextualTabGroupControlTemplate" TargetType="{x:Type Fluent:RibbonContextualTabGroup}">
        <Border x:Name="rootBorder" Visibility="{TemplateBinding InnerVisibility}"
                Margin="1,0,1,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                Width="Auto"
                Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}" 
                BorderThickness="1,0">
            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="0,0" 
                    VerticalAlignment="Top"
                    Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}">
                <Border.Margin>
                    <MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                        <Binding Source="{x:Static internal:DoubleUtil.Zero}" />
                        <Binding RelativeSource="{RelativeSource Self}"
                                 Path="(Fluent:RibbonProperties.TitleBarHeight)"
                                 Converter="{x:Static Converters:StaticConverters.InvertNumericConverter}" />
                    </MultiBinding>                    
                </Border.Margin>
                <Grid Margin="0"
                      VerticalAlignment="Top"
                      Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}">
                    <Rectangle Fill="{TemplateBinding Background}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                               Width="Auto" Height="Auto" >
                        <Rectangle.OpacityMask>
                            <SolidColorBrush Color="#14000000"/>
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <Rectangle Fill="{TemplateBinding BorderBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                               Width="Auto" Height="4" />
                    <Grid Margin="0,4,0,0">
                        <TextBlock Text="{TemplateBinding Header}"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Margin="6,0"
                                   TextTrimming="CharacterEllipsis"
                                   Foreground="{TemplateBinding Foreground}" />
                    </Grid>
                </Grid>
            </Border>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsWindowMaximized"
                     Value="True">
                <Setter Property="Margin"
                        TargetName="rootBorder"
                        Value="1,0,1,-0.1" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</ResourceDictionary>